package controllers;

import java.io.IOException;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

public class LanguageServlet extends HttpServlet {
	public void doGet(HttpServletRequest request, HttpServletResponse response)
		throws IOException {
		
		String path = ((HttpServletRequest) request).getRequestURI();
		String lang = path.toLowerCase().replaceAll("/l/", "");
		
		if (lang != null && !lang.isEmpty()) {
			HttpSession session = request.getSession(true);
			session.setAttribute("language", lang);
		}
		
		response.sendRedirect("/home");
	}
}
